package com.example.dmgame.adapter;

import java.util.List;

import com.example.dmgame.R;
import com.example.dmgame.bean.ChapterCommentListItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CommentAdapter extends BaseAdapter {
	List<ChapterCommentListItem> list;
	Context context;

	public CommentAdapter(List<ChapterCommentListItem> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if(convertView==null){
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.comment_item, null);
			holder.username = (TextView)convertView.findViewById(R.id.username);
			holder.floor = (TextView)convertView.findViewById(R.id.floor);
			holder.msg = (TextView)convertView.findViewById(R.id.msg);
			
			convertView.setTag(holder);
			
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		ChapterCommentListItem comment = list.get(position);
		holder.username.setText(comment.getUsername());
		holder.floor.setText("第"+comment.getFloor()+"楼");
		holder.msg.setText(comment.getMsg());
		return convertView;
	}
	
	private final class ViewHolder{
		TextView username;
		TextView floor;
		TextView msg;
	}

}
